﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Utilities;

namespace Repository
{
    public class SchedulerUtil
    {
        public static DataTable buildSchedulerDetailDataTable()
        {
            XMLGetter xmlGetter = new XMLGetter();
            xmlGetter.setXmlFilePath(Utilities.GlobalFile.SCHEDULER_FILENAME);
            xmlGetter.setMasterNode("SM2");
            xmlGetter.setHeaderNode("scheduler");
            xmlGetter.setLine1Node("setup");

            DataTable dtTarget = xmlGetter.getLine1NodeValues();
            return dtTarget;
        }

        public static string getAutoRun()
        {
            return Utilities.DataTableUtil.getValueByRowOrderColumnOrder(Repository.SchedulerUtil.buildSchedulerDetailDataTable(), 0, 1);
        }

        public static string getTestsuite()
        {
            return Utilities.DataTableUtil.getValueByRowOrderColumnOrder(Repository.SchedulerUtil.buildSchedulerDetailDataTable(), 0, 2);
        }

        public static string getRunsetup()
        {
            return Utilities.DataTableUtil.getValueByRowOrderColumnOrder(Repository.SchedulerUtil.buildSchedulerDetailDataTable(), 0, 3);
        }

        public static void setAUTORUN(string strAUTORUN)
        {
            XMLSetter xmlSetter = new XMLSetter();
            xmlSetter.setXmlFilePath(Utilities.GlobalFile.SCHEDULER_FILENAME);
            xmlSetter.setMasterNode("scheduler");
            xmlSetter.setHeaderNode("setup");

            //Save autorun
            xmlSetter.setHeaderNodeValue("id", "scheduler", "autorun", strAUTORUN);
        }

        public static void setTESTSUITE(string strTESTSUITE)
        {
            XMLSetter xmlSetter = new XMLSetter();
            xmlSetter.setXmlFilePath(Utilities.GlobalFile.SCHEDULER_FILENAME);
            xmlSetter.setMasterNode("scheduler");
            xmlSetter.setHeaderNode("setup");
            //Save testsuite
            xmlSetter.setHeaderNodeValue("id", "scheduler", "testsuite", strTESTSUITE);
        }

        public static void setRUNSETUP(string strRUNSETUP)
        {
            XMLSetter xmlSetter = new XMLSetter();
            xmlSetter.setXmlFilePath(Utilities.GlobalFile.SCHEDULER_FILENAME);
            xmlSetter.setMasterNode("scheduler");
            xmlSetter.setHeaderNode("setup");
            //Save runsetup
            xmlSetter.setHeaderNodeValue("id", "scheduler", "runsetup", strRUNSETUP);
        }
    }
}
